package com.qf.demo.votingSystem.controller;

import com.qf.demo.votingSystem.service.ICandidateNameService;
import com.qf.demo.votingSystem.vo.ResultVo;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import jdk.nashorn.internal.parser.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Victor
 * @since 2023-02-25
 */
@RestController
@RequestMapping("/votingSystem")
public class CandidateNameController {
    @Autowired
    ICandidateNameService iCandidateNameService;

    public static String token(){
        JwtBuilder builder = Jwts.builder();

        String token = builder//jwt主题
                .setIssuedAt(new Date())                            //设置token的生成时间
                .setId("123456")               //jwt 的唯一标识
                .setExpiration(new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000)) //设置过期时间
                .signWith(SignatureAlgorithm.HS256, "QIANfeng6666")     //设置加密方式和加密密码
                .compact();

        return token;





    }
    @GetMapping("/voting")
    public ResultVo voting(String phoneNUm,String v_name) throws Exception {

        final String token = token();
        if (token!=null){

        iCandidateNameService.putVoting(v_name);


        }

        return null;
    }


}
